package com.cat.dataStructure;

import java.util.ArrayDeque;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/check-if-word-is-valid-after-substitutions/
 * @create 2025/9/9 09:20
 * @since JDK17
 */

public class Solution63 {
    public boolean isValid(String str) {
        char[] s = str.toCharArray();
        if (s.length % 3 != 0) {
            return false;
        }
        int i = 0;
        for (var c : s) {
            if (c > 'a' && (i == 0 || c - s[--i] != 1)) {
                return false;
            }
            if (c < 'c') {
                s[i++] = c;
            }
        }
        return true;
    }
}
